package com.software.software.mapper;

import com.software.software.model.blogInfo;
import com.software.software.model.commentInfo;
import com.software.software.model.fileInfo;
import com.software.software.model.userInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

//该类是操作数据库的类
@Mapper
public interface UserMapper {
    @Insert("insert into userInfo(loginName, loginPwd, userName,userEmail, userPhone, userState) " +
            "values(#{loginName},md5(#{loginPwd}),#{loginName},#{userEmail},#{userPhone},1)")
    int save(Map<String, String> param);
    List<blogInfo> search(Map<String, String> param);
    @Insert("insert into blogInfo(userId, createDate, content,star, blogState, blogTitle) " +
            "values(#{userId},#{createDate},#{content},#{star},#{blogState},#{blogTitle})")
    int saveBlog(Map<String, String> param);
    @Insert("insert into fileInfo(userId, fileName, fileUrl) " +
            "values(#{userId},#{fileName},#{fileUrl})")
    int savefile(fileInfo file);
    @Insert("insert into tagInfo(content, tagId) " +
            "values(#{content},#{tagId})")
    int saveTagInfo(Map<String,String> m);
    @Update("alter table `blogtags` add column `${tableId}` int(1) null default 0")
    int saveBlogTag(int tableId);
    @Insert("insert into blogtags " +
            "values(${blogTagsInfo})")
    int saveTags(String blogTagsInfo);
    @Update("update blogtags set ${blogTagsInfo}")
    int updateTags(String blogTagsInfo);
    // 根据用户名查询密码
    String searchPwd(String loginName);

    // 查博客
    blogInfo searchBlog(String blogId);

    // 找评论
    List<commentInfo> searchComments(int blogId);

    commentInfo searchComment(String commentId);

    // 添加评论
    int saveComment(commentInfo commentInfo);

    // 更新博客
    int upDateBlog(Map<String, String> blog);

    @Update("update fileInfo set fileState = 0 where fileId = #{fileId}")
    int deleteFile(String fileId);
    // 删除博客
    int deleteBlog(String blogId);

    int deleteUser(String userId);

    int deleteComment(String commentId);

    // 搜用户
    List<userInfo> searchUser(Map<String,String> userInfo);

    userInfo searchUserInfo(Map<String,String> userInfo);

    int upDateUserInfo(Map<String, String> userInfo);

    int countCommonUser(Map<String, String> userInfo);

    int countFiles(String s);

    int countBlogs(String s);

    int countComments(String s);

    fileInfo searchCommonFile(Map<String,String> m);

    int upDateUserPwd(Map<String,String> m);

    // 查找所有的tag名字
    List<String> allTagsName();

    List<Integer> searchByTagId(int tagId);

    // 查找每一个blog对应的tag代号
    Map<String,Integer> getBlogTagId(int blogId);

    int changeHaveFace(Map<String, Integer> m);

    @Select("select * from fileInfo where fileState = 1")
    List<fileInfo> searchFiles();

}


